<template>
  <div class="handler-time-control">
    <a-select
      v-model:value="val.type"
      :options="options"
      placeholder="请选择"
    />
    <template v-if="val.type === 'custom'">
      <div class="box">
        <a-input v-model:value="val.data" placeholder="请输入" />
        <span class="text">小时</span>
      </div>
      <div>
        <p>超时处理方式</p>
        <a-select
          v-model:value="val.commitType"
          :options="commitTypeOptions"
          placeholder="请选择"
        />
      </div>
    </template>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue';

export default defineComponent({
  name: 'HandlerTimeControl',
  props: {
    value: {
      type: Object,
      default: () => ({}),
    },
    controls: {
      type: Object,
      default: () => ({}),
    },
    controlKey: {
      type: String,
      default: () => '',
    },
    options: {
      type: Object,
      default: () => ({}),
    },
    commitTypeOptions: {
      type: Object,
      default: () => ({}),
    },
  },
  setup(props, context) {
    const val = computed({
      get: () => props.value,
      set: (val) =>
        context.emit('updateValue', val, props.controlKey, props.controls),
    });

    return {
      val,
    };
  },
});
</script>

<style lang="less" scoped>
.handler-time-control {
  .ant-input {
    border-radius: 4px;
  }
  .ant-select {
    width: 100%;
    border-radius: 4px;
  }
  :deep .ant-select-selector {
    border-radius: 4px;
  }
  .box {
    .flexRow();
    margin: 8px 0;
    .text {
      padding-left: 4px;
      white-space: nowrap;
    }
  }
}
</style>
